﻿using System.Security.Cryptography;
using System.Text;

namespace ITTestingSystem.BusinessLogic.PasswordHasher
{
    /// <summary>
    /// 
    /// </summary>
    /// 
    public class PasswordHasher : IPasswordHasher
    {
        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="password">
        /// 
        /// </param>
        /// 
        /// <returns>
        /// 
        /// </returns>
        /// 
        string IPasswordHasher.GetPasswordHash(string password)
        {
            var hasher = MD5.Create();

            var passwordBytes = Encoding.ASCII.GetBytes(password);
            var passwordBytesHash = hasher.ComputeHash(passwordBytes);

            var hashBuilder = new StringBuilder();

            foreach (var passwordByte in passwordBytesHash)
            {
                hashBuilder.Append(passwordByte.ToString("x2"));
            }

            return hashBuilder.ToString();
        }
    }
}